package com.hyj.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyj.service.ParentModulesService;
import com.hyj.mapper.ParentModulesMapper;
import com.hyj.entity.Modules;
import com.hyj.entity.ParentModules;
import com.hyj.util.CommonUtil;

@Service
public class ParentModulesServiceImp implements ParentModulesService {
	@Autowired
	private ParentModulesMapper parentModulesmapper;

	@Override
	public List<ParentModules> selectByparentId(List<Integer> list) {
		// TODO Auto-generated method stub
		return parentModulesmapper.selectByparentId(list);
	}

	@Override
	public List<ParentModules> selectParentModulesAll() {
		// TODO Auto-generated method stub
		return parentModulesmapper.selectParentModules();
	}

	@Override
	public Integer addParentModules(ParentModules parentModules) {
		// TODO Auto-generated method stub
		Integer addParentModules=null;
		List<ParentModules> selectByName = parentModulesmapper.selectByName(parentModules);
		if(selectByName.size()==0){
			parentModulesmapper.addParentModules(parentModules);
		}else{
			addParentModules=-1;
		}
		return addParentModules;
	}

	@Override
	public Map<String, Object> deleteParentModules(Integer id) {
		// TODO Auto-generated method stub
		Map<String, Object> map = CommonUtil.getResultMap();
		List<Modules> selectModulesByRoleId = parentModulesmapper.selectModulesByRoleId(id);
		if(selectModulesByRoleId.size()!=0) {
			map.put("success", false);
			map.put("message", "该模块已存在子模块，不可删除！！！");
		}else {
			parentModulesmapper.deleteParentModules(id);
			map.put("success", true);
			map.put("message", "删除成功！！！");
		}
		return map;
	}

	@Override
	public Integer updateparentModule(Modules modules) {
		// TODO Auto-generated method stub
		return parentModulesmapper.updateparentModule(modules);
	};

	 

}
